// record.h : record
// CopyRight (c) 2009 fake, Inc. All Rights Reserved.
// fake@fake.cn
// 2009-09

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <string>

#ifndef INCLUDED_RECORD_H
#define INCLUDED_RECORD_H

class Record {
public:
	uint32_t ip;
	std::string country;
	std::string area;

	Record( void ) { Reset(); }
	inline void Reset( void ) { ip = 0; country.clear(); area.clear(); }

	int FromAddr( const size_t addr );
private:
	int get_area( size_t start );
};

// Records included the head ( 8 byte )
class Records {
public:
	size_t size;
	unsigned char *data;

	Records( void ) : size( 0 ), data( NULL ) {};
	~Records( void );

	int Load( FILE *fp, const size_t end );
	long GetString( std::string &str, size_t start ); // return scaned length
	int GetLong3( uint32_t &addr, size_t start );
};

extern Records g_records;

#endif // INCLUDED_RECORD_H
